/**
* @author Ashish Gupta
* CVSSP, University of Surrey
* Copyright (c) 2010 Ashish Gupta
* All rights reserved.
*/
/**
 * 
 */
package configuration;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author Ashish
 *
 */
public class GenePoolConfiguration {
	private Double proportionKeysToMutateInBlockMutation = 0.1; // default proportion is 10%
	private Double proportionKeysToMutateInCrossOverMutation = 0.1; // default proportion is 10%
	private Integer numGenerations = 0;
	private Integer numChromosomes = 0;
	private Integer numGenes = 0;

	/**
	 * @param string
	 * @throws IOException 
	 */
	public GenePoolConfiguration(String genePoolConfigFilename) throws IOException {
		File file = new File(genePoolConfigFilename);
		FileReader fr = new FileReader(file);
		BufferedReader br =new BufferedReader(fr);
		Map<Object,Object>gpcMap = new HashMap<Object,Object>();
		String line = null;
		while((line=br.readLine())!=null){
			if(!(line.startsWith("#", 0))){
				String[] inLine = line.split(":");
				Object key = inLine[0];
				Object value = inLine[1];
				gpcMap.put(key, value);
			}
		}
		br.close();
		fr.close();
		this.numGenerations = Integer.parseInt((String) gpcMap.get("numGenerations"));
		this.numChromosomes = Integer.parseInt((String) gpcMap.get("numChromosomes")) ;
		this.numGenes = Integer.parseInt((String) gpcMap.get("numGenes"));
		this.proportionKeysToMutateInBlockMutation = Double.parseDouble((String) gpcMap.get("proportionKeysToMutateInBlockMutation"));
		this.proportionKeysToMutateInCrossOverMutation = Double.parseDouble((String) gpcMap.get("proportionKeysToMutateInCrossOverMutation"));
	}

	/**
	 * @param proportionKeysToMutateInBlockMutation the proportionKeysToMutateInBlockMutation to set
	 */
	public void setProportionKeysToMutateInBlockMutation(
			Double proportionKeysToMutateInBlockMutation) {
		this.proportionKeysToMutateInBlockMutation = proportionKeysToMutateInBlockMutation;
	}

	/**
	 * @return the proportionKeysToMutateInBlockMutation
	 */
	public Double getProportionKeysToMutateInBlockMutation() {
		return proportionKeysToMutateInBlockMutation;
	}

	/**
	 * @param proportionKeysToMutateInCrossOverMutation the proportionKeysToMutateInCrossOverMutation to set
	 */
	public void setProportionKeysToMutateInCrossOverMutation(
			Double proportionKeysToMutateInCrossOverMutation) {
		this.proportionKeysToMutateInCrossOverMutation = proportionKeysToMutateInCrossOverMutation;
	}

	/**
	 * @return the proportionKeysToMutateInCrossOverMutation
	 */
	public Double getProportionKeysToMutateInCrossOverMutation() {
		return proportionKeysToMutateInCrossOverMutation;
	}

	/**
	 * @param numGenerations the numGenerations to set
	 */
	public void setNumGenerations(Integer numGenerations) {
		this.numGenerations = numGenerations;
	}

	/**
	 * @return the numGenerations
	 */
	public Integer getNumGenerations() {
		return numGenerations;
	}

	/**
	 * @param numChromosomes the numChromosomes to set
	 */
	public void setNumChromosomes(Integer numChromosomes) {
		this.numChromosomes = numChromosomes;
	}

	/**
	 * @return the numChromosomes
	 */
	public Integer getNumChromosomes() {
		return numChromosomes;
	}

	/**
	 * @param numGenes the numGenes to set
	 */
	public void setNumGenes(Integer numGenes) {
		this.numGenes = numGenes;
	}

	/**
	 * @return the numGenes
	 */
	public Integer getNumGenes() {
		return numGenes;
	}

}
